local path "C:\Users\pgi1\Dropbox\Coal 2021 _ Joe Peter\Bank Regressions\"
cd "`path'\data"
set seed 100
set more off
clear



use  loan_year_vars_dataset, clear

keep if year>=2000 & year<=2020

bysort ultimateparentid year : keep if _n==1

replace  deal_amount_mtr= deal_amount_mtr/1000000000

keep if treated_ever==1
// now generate event time dataset
gen t=year-minpolicyyear

preserve
collapse loans_mtr deal_amount_mtr, by(t)
rename loans_mtr loans_mtr_all
rename deal_amount_mtr deal_amount_mtr_all
save loans-time, replace
restore

gen early_policy=(minpolicyyear>=2008 & minpolicyyear<=2013)
collapse loans_mtr deal_amount_mtr , by(t early_policy)
joinby t using loans-time
keep if t>=-5 & t<=5

twoway (scatter  loans_mtr_all t , connect(l) lpattern(solid) msymbol(O) color(black)  lwidth(medthick)) /// 
(scatter  loans_mtr t if early_policy==1, connect(l) lpattern(dash) msymbol(S) color(red)  lwidth(medthick)) /// 
(scatter  loans_mtr t if early_policy==0, connect(l) lpattern(shortdash) msymbol(D) color(green)  lwidth(medthick)) /// 
, scheme(s2mono) graphregion(fcolor(white)) bgcolor(white)  xlabel(-5(1)5) xtitle("Event Time") ytitle("Average Number of MTR Loans") ///
ylabel(0 (0.5) 3, nogrid ) xline(0,lpattern(dash) lcolor(blue) lwidth(thin)) ///
yline(0 (0.5) 3, lpattern(shortdash) lcolor(gs10) lwidth(thin)) ///
legend( row(2) order(1 2 3) lab(1 "All Treated Banks") lab(2 "Early Treated Banks") lab(3 "Late Treated Banks") )  ///
ysize(3.75) xsize(5)

graph export  "`path'\figures\figure2A.emf", as(emf) replace


twoway (scatter  deal_amount_mtr_all t , connect(l) lpattern(solid) msymbol(O) color(black)  lwidth(medthick)) /// 
(scatter  deal_amount_mtr t if early_policy==1, connect(l) lpattern(dash) msymbol(S) color(red)  lwidth(medthick)) /// 
(scatter  deal_amount_mtr t if early_policy==0, connect(l) lpattern(shortdash) msymbol(D) color(green)  lwidth(medthick)) /// 
, scheme(s2mono) graphregion(fcolor(white)) bgcolor(white)  xlabel(-5(1)5) xtitle("Event Time") ytitle("Average MTR Loan Amounts ($ Billions)") ///
ylabel(0 (1) 7, nogrid )   xline(0,lpattern(dash) lcolor(blue) lwidth(thin)) ///
yline(0 (1) 7, lpattern(shortdash) lcolor(gs12) lwidth(thin)) ///
legend( row(2) order(1 2 3) lab(1 "All Treated Banks") lab(2 "Early Treated Banks") lab(3 "Late Treated Banks") )  ///
ysize(3.75) xsize(5)

graph export  "`path'\figures\figure2B.emf", as(emf) replace

  
 exit 

////////////////////////////////////////////
// Tabulate for all policies

preserve

collapse loans_mtr deal_amount_mtr, by(t)

keep if t>=-5 & t<=5

twoway (scatter  loans_mtr t, connect(l) lpattern(solid) msymbol(O) color(red)  lwidth(medthick)) /// 
(scatter  loans_mtr_nontr t, connect(l) lpattern(solid) msymbol(O) color(green)  lwidth(medthick)) /// 
  , scheme(s2mono) graphregion(fcolor(white)) bgcolor(white)  xlabel(-5(1)5) xtitle("Event Time") ytitle("Average MTR Loans") ///
    ylabel(0 (0.2) 1.6, nogrid ) xline(0,lpattern(dash) lcolor(blue) lwidth(thin)) ///
	 yline(0 (0.2) 1.6, lpattern(shortdash) lcolor(gs10) lwidth(thin)) ///
   legend( row(1) order(1 2 ) lab(1 "Treated Banks") lab(2 "UnTreated Banks") )  ///
  ysize(3.75) xsize(5)
 
 
graph export  "`path'\figures\figure2A.emf", as(emf) replace    
  
  twoway (scatter  deal_amount_mtr t, connect(l) lpattern(solid) msymbol(O) color(red)  lwidth(medthick)) /// 
(scatter  deal_amount_mtr_nontr t, connect(l) lpattern(solid) msymbol(O) color(green)  lwidth(medthick)) /// 
  , scheme(s2mono) graphregion(fcolor(white)) bgcolor(white)  xlabel(-5(1)5) xtitle("Event Time") ytitle("Average MTR Loan Amounts ($ Billions)") ///
      ylabel(0 (1) 4, nogrid )   xline(0,lpattern(dash) lcolor(blue) lwidth(thin)) ///
	 yline(0 (1) 4, lpattern(shortdash) lcolor(gs12) lwidth(thin)) ///
   legend( row(1) order(1 2 ) lab(1 "Treated Banks") lab(2 "UnTreated Banks") )  ///
  ysize(3.75) xsize(5)
  
  
graph export  "`path'\figures\figure2B.emf", as(emf) replace   



restore
  
  
gen early_policy=(minpolicyyear>=2008 & minpolicyyear<=2013)

collapse loans_mtr deal_amount_mtr , by(t early_policy)

keep if t>=-5 & t<=5

twoway (scatter  loans_mtr t if early_policy==1, connect(l) lpattern(solid) msymbol(O) color(red)  lwidth(medthick)) /// 
(scatter  loans_mtr t if early_policy==0, connect(l) lpattern(solid) msymbol(O) color(green)  lwidth(medthick)) /// 
  , scheme(s2mono) graphregion(fcolor(white)) bgcolor(white)  xlabel(-5(1)5) xtitle("Event Time") ytitle("Average MTR Loans") ///
    ylabel(0 (0.5) 3, nogrid ) xline(0,lpattern(dash) lcolor(blue) lwidth(thin)) ///
	 yline(0 (0.5) 3, lpattern(shortdash) lcolor(gs10) lwidth(thin)) ///
   legend( row(1) order(1 2 ) lab(1 "Early Treated Banks") lab(2 "Late Treated Banks") )  ///
  ysize(3.75) xsize(5)

 
 graph export  "`path'\figures\figure2C.emf", as(emf) replace    
  
  twoway (scatter  deal_amount_mtr t if early_policy==1, connect(l) lpattern(solid) msymbol(O) color(red)  lwidth(medthick)) /// 
(scatter  deal_amount_mtr t if early_policy==0, connect(l) lpattern(solid) msymbol(O) color(green)  lwidth(medthick)) /// 
  , scheme(s2mono) graphregion(fcolor(white)) bgcolor(white)  xlabel(-5(1)5) xtitle("Event Time") ytitle("Average MTR Loan Amounts ($ Billions)") ///
      ylabel(0 (1) 7, nogrid )   xline(0,lpattern(dash) lcolor(blue) lwidth(thin)) ///
	 yline(0 (1) 7, lpattern(shortdash) lcolor(gs12) lwidth(thin)) ///
   legend( row(1) order(1 2 ) lab(1 "Early Treated Banks") lab(2 "Late Treated Banks") )  ///
  ysize(3.75) xsize(5)
  
  
  graph export  "`path'\figures\figure2D.emf", as(emf) replace   
  
  
  
  ////////////////////////////////////////////////////////////////
  // Tabulate stories
  
  use news-bank-data, clear

bysort pubid: keep if _n==1

gen national=regexm(Publication,"New York Times") | regexm(Publication,"Guardian")  | regexm(Publication,"Financial Times")

gen local=regexm(Publication,"Times-Tribune") |  regexm(Publication,"Pittsburgh Post-Gazette") |  regexm(Publication,"Pittsburgh Tribune Review") |  regexm(Publication,"Charleston Gazette")

gen x=1
gen year=year(Date)


collapse (sum) x national local, by(year)

keep if year<=2020

// add zero observation pre 2006
append using year-2000-2006.dta
sort year

twoway (scatter   national year, connect(l) lpattern(solid) msymbol(O) color(green)  lwidth(medthick)) /// 
(scatter   local year, connect(l) lpattern(solid) msymbol(O) color(blue)  lwidth(medthick)) ///
 (scatter  x year, connect(l) lpattern(solid) msymbol(O) color(red)  lwidth(medthick)) /// 
 ,scheme(s2mono) graphregion(fcolor(white)) bgcolor(white)  xlabel(2000(2)2020) xtitle("Year") ytitle("Number of Stories") ///
 ylabel(0 (10) 40, nogrid ) yline(0 (10) 40, lpattern(shortdash) lcolor(gs10) lwidth(thin)) ///
 legend( row(2) order(1 2 3) lab(1 "National Newspaper") lab(2 "Local Newspaper") lab(3 "Any") )  ysize(3.75) xsize(5)
 
   graph export  "`path'\figures\figure1.emf", as(emf) replace    
  exit
